---@class InvasionDamageItem : UIComponentBase
---@field New fun(parent:GComponent):InvasionDamageItem
local InvasionDamageItem = Class("InvasionTeamItem",UIComponentBase)
local t = InvasionDamageItem
function t:ctor(parent,id,_type)
    ---@type GComponent
    self.parent = parent
    self.id = id
    self.showType = _type
    if _type == 1 then
        self.fguiObj = newGComponent("FlyTestBoss","BattleItems")
    else
        self.fguiObj = newGComponent("FlyTestTeam","BattleItems")
    end
    local textMesh = self:GetChild("text")
    self.anim = self:GetTransition("Normal")
    self.normalAnim = self:GetTransition("Normal")
    self.HealAnim = self:GetTransition("Heal")
    self.critAnim = self:GetTransition("Crit")
    self.ctrlState = self:GetController("state")
    self.ctrlFont = self:GetController("font",textMesh)
    self.textList = {}
    for i = 0,4 do
        table.insert(self.textList,self:GetChild("n"..i,textMesh))
    end
    --self.ctrlSize = self:GetController("size")
    self.parent:AddChild(self.fguiObj)
    self:OnCreate()
end
function t:OnCreate()
    self.fguiObj.visible = true
    self.isDie = false
    self.during = 1
    self.curTime = 0
end
function t:OnDestroy()
    self:DelReferenceAll()
    self.textList = nil
end
function t:Update(dt)
    if self.isDie then return end
    self.curTime = self.curTime + dt
    if self.curTime > self.during then
        self.fguiObj.visible = false
        self.isDie = true
    end
end
function t:SetSize(isMy)
    --self.ctrlSize.selectedIndex = isMy and 0 or 1
end
function t:SetDamage(damage,damageType,sourceSkillId,x,y)
    x,y = TBS.Battle.SceneToScreenPoint(x,y,0)
    x,y = Util.FGUIScreenToLocal(self.parent,x,y,0,0)
    self.fguiObj:SetXY(x,y)
    local isNormal = false --普攻
    local showCfg = dataTable.getDataTableByStringId("t_collocationskillshow",sourceSkillId)
    if showCfg then
        isNormal = showCfg.f_SkillType == 1 and true or false
    end
    self.ctrlState.selectedIndex = 0
    local fontIndex = 3
    if damage >= 0 then
        if isNormal then
            if damageType == TBS.Config.DamageType.crit then
                self.critAnim:Play()
            else
                self.normalAnim:Play()
            end
        else
            fontIndex = 2
            if damageType == TBS.Config.DamageType.crit then
                self.critAnim:Play()
            else
                self.normalAnim:Play()
            end
        end
        self.ctrlFont.selectedIndex = fontIndex
        if damageType == TBS.Config.DamageType.shields then
            self.ctrlState.selectedIndex = 5
        elseif damageType == TBS.Config.DamageType.dodge then
            self.ctrlState.selectedIndex = 3
        else
            self.textList[fontIndex+1].text = tostring(damage)
        end
    else
        fontIndex = 1
        self.HealAnim:Play()
        self.ctrlFont.selectedIndex = fontIndex
        self.textList[fontIndex+1].text = tostring(math.abs(damage))
    end
    self.curTime = 0
end
function t:IsDie()
    return self.isDie
end
return t